$(function() {
	$('.car_use').on('click', function() {
		if($('.company_type').val() == 0) {
			choosecar("{:url('used/index',['op'=>'search'])}")
		} else {
			choosecar("{:url('used/index',['op'=>'search'])}?company_type=" + $('.company_type').val())
		}
	});
	$('.limit').on('click', function() {
		var limiturl = "{:url('limit',['op'=>'search'])}?car_use_id=" + $(this).closest('tr').data('id')
		console.log(limiturl)
		layer.open({
			type: 2,
			title: '请选择',
			shadeClose: true,
			shade: 0.8,
			area: ['80%', '70%'],
			content: limiturl //iframe的url
		});

	});

	$('.addlimit').on('click', function() {
		var that = this

		layer.open({
			type: 1,
			id: "delect",
			content: "<input type='number' class='chang_main' style='margin-left:5px'/>",
			btn: ['确定', '取消'],
			btnAlign: 'c' //按钮居中
				,
			shade: 0 //不显示遮罩
				,
			yes: function() {
				var limit = $(that).closest('tr').find('.limit_list').html() - 0
				var balance = $(that).closest('tr').find('.balance').html() - 0

				limit += $('.chang_main').val() - 0
				balance += $('.chang_main').val() - 0
				$.ajax({
					type: "post",
					data: {
						car_use_id: $(that).closest('tr').data('id'),
						quota: limit
					},
					url: "{:url('edit')}",
					success: function(res) {
						if(res.code == 1) {
							$(that).closest('tr').find('.limit_list').html(limit)
							$(that).closest('tr').find('.balance').html(balance)
							layer.closeAll();
						}
					}

				});

			},
			btn2: function() {
				layer.closeAll();
			}
		});
	});
	$('.reducelimit').on('click', function() {
		var that = this
		layer.open({
			type: 1,
			id: "delect",
			content: "<input type='number' class='chang_main' style='margin-left:5px'/>",
			btn: ['确定', '取消'],
			btnAlign: 'c' //按钮居中
				,
			shade: 0 //不显示遮罩
				,
			yes: function() {

				var limit = $(that).closest('tr').find('.limit_list').html() - 0
				var balance = $(that).closest('tr').find('.balance').html() - 0
				limit -= $('.chang_main').val() - 0
				balance -= $('.chang_main').val() - 0
				if(limit >= 0) {
//					if(balance >= 0) {
						$.ajax({
							type: "post",
							data: {
								car_use_id: $(that).closest('tr').data('id'),
								quota: limit
							},
							url: "{:url('edit')}",
							success: function(res) {
								if(res.code == 1) {
									$(that).closest('tr').find('.limit_list').html(limit)
									$(that).closest('tr').find('.balance').html(balance)
									layer.closeAll();
								}
							}

						});
//					}else{
//						Err('余额不能小于0')
//					}
				} else {
					Err('额度不能小于0')
				}

			},
			btn2: function() {
				layer.closeAll();
			}
		});
	});
})